﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using BLL;
using Enities;

namespace QLThuVien_Nhom21
{
    public partial class QLNhapTaiLieu : Form
    {
        private QLPhieuNhap _quanly;
        private PhieuNhap _phieunhap;
        private bool _isUpdate;

        public QLNhapTaiLieu(QLPhieuNhap qlpn, PhieuNhap pn = null)
            : this()
        {
            _quanly = qlpn;
            _phieunhap = pn;
            _isUpdate = (pn != null);
        }
        public QLNhapTaiLieu()
        {
            InitializeComponent();
            
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnLuuNhapTL_Click(object sender, EventArgs e)
        {

            //if (!_isUpdate) _phieunhap = new PhieuNhap();
            //_phieunhap.MaPhieuNhap = txtMaPhieuNhap.Text.ToString();
            //_phieunhap.NguoiLap = txtNguoiNhap.Text.ToString();
            //_phieunhap.NgayLap = dtpNgayNhap.Value;

            //var aResult = _quanly.InsertOrUpdate(_phieunhap);
            //if (aResult.Success)
            //    DialogResult = DialogResult.OK;
            //else
            //    MessageBox.Show(aResult.GetErrorMessages());

            int kq = ThemPN();
            if (kq == 1)
            {
                lblkqt.Text = "thêm phiếu nhập thành công !";
            }
            else
            {
                lblkqt.Text = "Thêm phiếu nhập không thành công !";
            }
            

        }

        private void txtMaPhieuNhap_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            txtMaPhieuNhap.Text = string.Empty;
            txtNguoiNhap.Text = string.Empty;

        }
        public int ThemPN()
        { 
            PhieuNhap p=new PhieuNhap();
            p.MaPhieuNhap=txtMaPhieuNhap.Text.ToString();
            p.NgayLap = DateTime.Now;
            p.NguoiLap=txtNguoiNhap.Text.ToString();
           bool kq=  PhieuNhap.Objects.InsertOrUpdate(p);
           if (kq == true)
           { return 1;}
           return 0;
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
